<template>
  <div>
    <div ref="captureElement" class="content-box">
      <h1>需要保存的内容</h1>
      <p>示例文本</p>
    </div>
    <button @click="saveAsImage">保存为图片</button>
  </div>
</template>

<script>
import domtoimage from 'dom-to-image';

export default {
  methods: {
    saveAsImage() {
      domtoimage.toPng(this.$refs.captureElement)
        .then(imgUrl => {
          const link = document.createElement('a');
          link.download = 'screenshot.png';
          link.href = imgUrl;
          link.click();
        });
    }
  }
};
</script>